package {
	import away3d.cameras.Camera3D;
	import away3d.cameras.lenses.ShadowBoxLens;
	import away3d.cameras.lenses.ShiftLens;
	import away3d.containers.Scene3D;
	import away3d.containers.View3D;
	import away3d.core.render.Renderer;
	import away3d.primitives.Cone;
	import away3d.primitives.Cube;
	import away3d.primitives.Plane;
	import away3d.primitives.Sphere;

	import flash.display.Sprite;

	/**
	 * @author JCGray
	 * @version1.0.0
	 * @date May 5, 2011
	 * @client Tuesday Creative
	 * @project Giggle Go
	 * @langversion ActionScript3.0
	 */
	public class LensShiftScene extends Sprite 
	{
		
		private var _view:View3D;
		private var _scene:Scene3D;
		private var _camera:Camera3D;
		private var _lense:ShadowBoxLens;
		
		private var _ball:Sphere;
		private var _cube:Cube;
		private var _cone:Cone;
		private var _ballon:Sphere;
		private var _room:Cube;
		
		private var _test:Sprite;
		
		
		public function LensShiftScene():void
		{
			
			trace("Lense Shift Scene called");
			
			_view = new View3D();
			_scene = _view.scene;
			_camera = _view.camera;
			_camera.y = 0;
			_camera.z = 0;
			
			//_view.x = 300;
			//_view.y = 300;
			
			_view.renderer = Renderer.BASIC;
			
			trace("lens is " + _camera.lens);
			_lense = new ShadowBoxLens();
			_camera.lens = _lense;
			
			trace("lense is " + _camera.lens);
			
			addChild(_view);
				
			
			_test = new Sprite();
			_test.graphics.beginFill(0x990099);
			_test.graphics.drawCircle(0, 0, 10);
		
			//addChild(_test);
			
			initObjects();
		}
		
		private function initObjects():void
		{
			trace("Lense Shift Scene initObjectsCalled");
			
			_ball = new Sphere({material:'red#', radius:25});
			_cube = new Cube( { height:50, width:50, depth:50 } );
			var cubeTwo:Cube = new Cube( { height:50, width:50, depth:50 } );
			var cubeThree:Cube = new Cube({height:200, width:200, depth:200});

			var _rightPlane:Plane = new Plane( { height:600, width:600 } );
			var _leftPlane:Plane = new Plane( { height:600, width :600 } );
			var _topPlane:Plane = new Plane( { height:600, width:600 } );
			var _bottomPlane:Plane = new Plane( { height:600, width :600 } );
			var _backPlane:Plane = new Plane( { height:600, width:600 } );
			_scene.addChild(_cube);
			
			_ball.x = 100;
			_ball.y = 100;
			_ball.z = 100;
			
			_cube.x = 0;
			_cube.y = 0;
			_cube.z = 100;
			
			cubeTwo.x = -100;
			cubeTwo.y = 50;
			cubeTwo.z = 300;
			
			cubeThree.x = 200;
			cubeThree.y = -200;
			cubeThree.z = 400;
			
			_topPlane.x = 0;
			_topPlane.y = 300;
			_topPlane.z = 300;
			
			_bottomPlane.x = 0;
			_bottomPlane.y = -300;
			_bottomPlane.z = 300;
			_bottomPlane.bothsides = true;
			
			_leftPlane.x = -300;
			_leftPlane.y = 0;
			_leftPlane.z = 300;
			_leftPlane.rotationZ = 90;
			_leftPlane.bothsides = true;
			
			_rightPlane.x = 300;
			_rightPlane.y = 0;
			_rightPlane.z = 300;
			_rightPlane.rotationZ = -90;
			
			_backPlane.x = 0;
			_backPlane.y = 0;
			_backPlane.z = 600;
			_backPlane.rotationX = 90;
			
			_scene.addChild(_topPlane);
			_scene.addChild(_bottomPlane);
			_scene.addChild(_leftPlane);
			_scene.addChild(_rightPlane);
			_scene.addChild(_backPlane);
			
			_scene.addChild(_cube);
			_scene.addChild(cubeTwo);
			_scene.addChild(cubeThree);
			
			_view.render();
			
		}
		
		public function updateAngle(boxX:Number, boxY:Number, boxWidth:Number):void
		{
			trace("update angles called" + boxX);
			var hoX:Number = boxX;
			var hoY:Number = boxY;
			var hoCombined:Number = Math.sqrt(   (Math.abs(hoX) * Math.abs(hoX))  + ( Math.abs(hoY) * Math.abs(hoY))  );
			
			//var hdCenter:Number = boxWidth * CALC;
			var hdCenter:Number = 2000;
			
			var hd:Number = Math.sqrt(  (hdCenter * hdCenter)  -  (hoCombined * hoCombined)   );
			
			_lense.updatePerspective(hd, hoX, hoY);
			
			//_ball.x = val;
			//_lense.upateFustrum(xVal, yVal);
			//_camera.x = val;
			_cube.z += 1;
			_view.render();
			
		}
	}
}
